home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 29
/
Volume 29 - JOGO DISK .iso
/
Games
/
jungle_adventure.swf
/
scripts
/
__Packages
/
SSDrawing.as
< prev
next >
Wrap
Text File
|
2006-11-29
|
12KB
|
398 lines
class SSDrawing
{
static var GRADIENT_ALPHAS = [100,100];
static var GRADIENT_RATIOS = [0,255];
static var styles = {};
var edgeGroupMask = SSGlobal.EDGE_GROUPING_MASK;
var created = 0;
var stylePrepared = false;
var className = "SSDrawStyle";
function SSDrawing(obj)
{
if(!this.lightDirection)
{
this.lightDirection = SSGlobal.DRAW_LIGHT_DIRECTION;
}
this.inst = [];
this.iLayers = [];
}
function initStyle(force)
{
if(!SSDrawing.styles[this.className])
{
this.setup();
this.define();
this.defineFromXML();
this.prepare();
SSDrawing.styles[this.className] = this;
}
}
function init(points, edges)
{
this.points = points;
this.edges = edges;
this.__proto__.initStyle();
var _loc5_ = undefined;
var _loc4_ = undefined;
this.groups = [];
var _loc2_ = -1;
var _loc6_ = edges.length;
while((_loc2_ = _loc2_ + 1) < _loc6_)
{
if(_loc4_ != (_loc4_ = edges[_loc2_].props & this.edgeGroupMask))
{
this.groups.push(_loc5_ = [edges[_loc2_]]);
_loc5_.mask = _loc4_;
}
else
{
_loc5_.push(edges[_loc2_]);
}
edges[_loc2_].attributes = this.pickStyle(_loc4_);
}
if(this.groups.length > 1 && _loc5_ != edges[0] && _loc4_ == (edges[0].props & this.edgeGroupMask))
{
this.groups[0] = this.groups.pop().concat(this.groups[0]);
this.groups[0].mask = _loc4_;
}
this.process();
}
function process()
{
this.showInfo();
}
function calculateLighting(normal, ambient, diffuse, specular)
{
var _loc3_ = undefined;
if((_loc3_ = Math.sin(this.lightDirection.dot(normal) * 1.570796)) <= 0)
{
return new RGB(diffuse.r - (specular.r - diffuse.r) * _loc3_,diffuse.g - (specular.g - diffuse.g) * _loc3_,diffuse.b - (specular.b - diffuse.b) * _loc3_);
}
return new RGB(diffuse.r + (ambient.r - diffuse.r) * _loc3_,diffuse.g + (ambient.g - diffuse.g) * _loc3_,diffuse.b + (ambient.b - diffuse.b) * _loc3_);
}
function draw(root)
{
this.root = this.target = root;
this.target.clear();
this.created = 0;
var _loc3_ = this.inst;
var _loc2_ = -1;
var _loc4_ = _loc3_.length;
while((_loc2_ = _loc2_ + 1) < _loc4_)
{
_loc3_[_loc2_][0].apply(this,_loc3_[_loc2_][1]);
}
}
function instruction(method)
{
this.inst.push([method,arguments.slice(1)]);
}
function solidShape(color)
{
this.inst.push([this._solid,arguments]);
}
function bitmapShape(textureID, p)
{
var _loc9_ = _global.root.attachMovie(textureID,"tmp",834201);
var _loc12_ = _loc9_._width;
var _loc11_ = _loc9_._height;
_loc9_.removeMovieClip();
var _loc3_ = p.length;
var _loc6_ = undefined;
var _loc5_ = undefined;
var _loc8_ = undefined;
var _loc7_ = undefined;
_loc6_ = _loc8_ = p[0].x;
_loc5_ = _loc7_ = p[0].y;
while((_loc3_ = _loc3_ - 1) > 0)
{
_loc6_ = Math.min(p[_loc3_].x,_loc6_);
_loc5_ = Math.min(p[_loc3_].y,_loc5_);
_loc8_ = Math.max(p[_loc3_].x,_loc8_);
_loc7_ = Math.max(p[_loc3_].y,_loc7_);
}
var _loc10_ = Math.ceil((_loc8_ - _loc6_) / _loc12_);
var _loc13_ = Math.ceil((_loc7_ - _loc5_) / _loc11_);
this.inst.push([this._bitmapShape,[textureID,p,_loc6_,_loc5_,_loc12_,_loc11_,_loc10_,_loc10_ * _loc13_]]);
}
function gradientShape()
{
this.inst.push([this._gradient,arguments]);
}
function assetStrip(linkageID, from, to, tile, skewOnX, skewOnY)
{
if(linkageID == null || from == null || to == null)
{
return undefined;
}
var _loc3_ = new Vector(to.x - from.x,to.y - from.y,0);
if(skewOnX == null)
{
skewOnX = true;
}
if(skewOnY == null)
{
skewOnY = true;
}
var _loc4_ = Math.atan2(_loc3_.y,_loc3_.x) * 180 / 3.141592653589793;
this.inst.push([this._assetStrip,[linkageID,from.x,from.y,_loc3_.length,tile,!skewOnX ? 0 : _loc4_,!skewOnY ? 0 : _loc4_]]);
}
function textureStrip(linkageID, from, to, tile, skewX)
{
if(linkageID == null || from == null || to == null)
{
return undefined;
}
var _loc3_ = new Vector(to.x - from.x,to.y - from.y,0);
this.inst.push([this._assetStrip,[linkageID,from.x,from.y,_loc3_.length,tile,!skewX ? 0 : skewX,Math.atan2(_loc3_.y,_loc3_.x) * 180 / 3.141592653589793]]);
}
function transform()
{
if(arguments.length)
{
this.inst.push([this._transform,arguments]);
}
}
function _transform(x, y, rot)
{
this.target._x = x;
this.target._y = y;
this.target._rotation = rot;
}
function _assetStrip(linkageID, x, y, len, tile, skewX, skewY)
{
var _loc13_ = undefined;
var _loc8_ = skewX != skewY;
if(_loc8_)
{
var _loc4_ = MovieClipSkew.create(this.target,null,"mc" + this.created,++this.created);
_loc4_.skew(skewX,skewY);
}
else
{
_loc4_ = this.target.createEmptyMovieClip("mc" + this.created,++this.created);
_loc4_._rotation = skewX;
}
_loc4_._x = x;
_loc4_._y = y;
var _loc3_ = _loc4_.attachMovie(linkageID,"m0",0);
var _loc5_ = _loc3_._width;
var _loc7_ = 1;
if(tile)
{
var _loc2_ = _loc7_ = Math.max(1,Math.round(len / _loc5_));
while(_loc2_ = _loc2_ - 1)
{
_loc3_ = _loc4_.attachMovie(linkageID,"m" + _loc2_,_loc2_);
_loc3_._x = _loc2_ * _loc5_;
}
}
if(_loc8_)
{
_loc4_.asset._xscale = len / (!tile ? _loc5_ : _loc7_ * _loc5_) * 100 + 1;
}
else
{
_loc4_._xscale = len / (!tile ? _loc5_ : _loc7_ * _loc5_) * 100;
}
}
function createTarget(targetName, depth, linkageID)
{
if(linkageID != null)
{
this.inst.push([linkageID != null ? this._createAssetTarget : this._createEmptyTarget,arguments]);
}
}
function setTarget(targetName)
{
this.inst.push([this._setTarget,arguments]);
}
function setLayer(layerNum)
{
if(this.iLayers[layerNum])
{
this.goRootTarget("mc" + layerNum);
}
else
{
this.inst.push([this._setLayer,arguments]);
this.iLayers[layerNum] = true;
}
}
function _setLayer(num)
{
this.target = this.root.createEmptyMovieClip("mc" + num,num);
}
function goRoot()
{
this.inst.push([this._goRoot,arguments]);
}
function goRootTarget()
{
this.inst.push([this._goRootTarget,arguments]);
}
function attachAndPlaceMovie()
{
this.inst.push([this._attachAndPlaceMC,arguments]);
}
function showInfo()
{
this.inst.push([this._showInfo]);
}
function _solid(color, p)
{
var _loc5_ = this.target;
_loc5_.beginFill(color);
var _loc3_ = undefined;
if(arguments.length > 2)
{
var _loc6_ = arguments.length;
while(_loc6_ = _loc6_ - 1)
{
_loc3_ = p = arguments[_loc6_].length;
_loc5_.moveTo(p[0].x,p[0].y);
while((_loc3_ = _loc3_ - 1) > -1)
{
_loc5_.lineTo(p[_loc3_].x,p[_loc3_].y);
}
}
}
else
{
_loc3_ = p.length;
_loc5_.moveTo(p[0].x,p[0].y);
while((_loc3_ = _loc3_ - 1) > -1)
{
_loc5_.lineTo(p[_loc3_].x,p[_loc3_].y);
}
}
_loc5_.endFill();
}
function _gradient(type, colors, alphas, ratios, matrix, p)
{
var _loc4_ = this.target;
_loc4_.beginGradientFill(type,colors,alphas,ratios,matrix);
var _loc2_ = p.length;
_loc4_.moveTo(p[0].x,p[0].y);
while((_loc2_ = _loc2_ - 1) > -1)
{
_loc4_.lineTo(p[_loc2_].x,p[_loc2_].y);
}
_loc4_.endFill();
}
function _bitmapShape(tileID, p, l, t, w, h, tw, i)
{
var _loc3_ = undefined;
var _loc7_ = this.target.createEmptyMovieClip("_T" + this.created,++this.created);
_loc7_._x = l;
_loc7_._y = t;
while((i = i - 1) > -1)
{
_loc3_ = _loc7_.attachMovie(tileID,"m" + i,i);
_loc3_._x = i % tw * w;
_loc3_._y = Math.floor(i / tw) * h;
}
var _loc6_ = this.target.createEmptyMovieClip("_F" + this.created,++this.created);
_loc6_.beginFill(0);
i = p.length;
_loc6_.moveTo(p[0].x,p[0].y);
while(i = i - 1)
{
_loc6_.lineTo(p[i].x,p[i].y);
}
_loc6_.endFill();
_loc7_.setMask(_loc6_);
}
function _createEmptyTarget(name, depth)
{
if(name == null)
{
name = "CLIP" + this.created;
}
else if(this.target[name])
{
return undefined;
}
this.target.createEmptyMovieClip(name,!depth ? this.created : depth);
this.created = this.created + 1;
}
function _createAssetTarget(name, depth, linkageID)
{
if(name == null)
{
name = "CLIP" + this.created;
}
else if(this.target[name])
{
return undefined;
}
this.target.attachMovie(linkageID,name,!depth ? this.created : depth);
this.created = this.created + 1;
}
function _createTarget(name, depth, linkageID)
{
if(this.target[name])
{
return undefined;
}
if(name == null)
{
name = "mc" + this.created;
}
if(linkageID != null)
{
this.target.attachMovie(linkageID,name,!depth ? this.created : depth);
}
else
{
this.target.createEmptyMovieClip(name,!depth ? this.created : depth);
}
this.created = this.created + 1;
}
function _setTarget(name)
{
this.target = this.target[name];
}
function _goRoot()
{
this.target = this.root;
}
function _goRootTarget(name)
{
this.target = this.root[name];
}
function _attachAndPlaceMC(assetID, depth, x, y)
{
var _loc2_ = this.target.attachMovie(assetID,assetID + "_" + depth,depth);
_loc2_._x = x;
_loc2_._y = y;
}
function _showInfo()
{
var _loc4_ = this.edges.length;
if(this.target != this.root)
{
this.target = this.root;
}
var _loc3_ = this.target.createEmptyMovieClip("info",65535);
var _loc2_ = undefined;
while((_loc4_ = _loc4_ - 1) > -1)
{
_loc2_ = this.edges[_loc4_];
_loc3_.lineStyle(0,(_loc2_.props & 1) == 0 ? 13421772 : 16711680);
_loc3_.moveTo(_loc2_.a.x + _loc2_.span.x,_loc2_.a.y + _loc2_.span.y);
_loc3_.lineTo(_loc2_.a.x,_loc2_.a.y);
_loc3_.lineStyle(3,255);
_loc3_.moveTo(_loc2_.a.x + _loc2_.span.x * 0.5,_loc2_.a.y + _loc2_.span.y * 0.5);
_loc3_.lineTo(_loc2_.a.x + _loc2_.span.x * 0.5 + _loc2_.normal.x * 30,_loc2_.a.y + _loc2_.span.y * 0.5 + _loc2_.normal.y * 30);
_loc3_.lineStyle(3,65280);
_loc3_.moveTo(_loc2_.a.x,_loc2_.a.y);
_loc3_.lineTo(_loc2_.a.x + _loc2_.a.normal.x * 30,_loc2_.a.y + _loc2_.a.normal.y * 30);
}
}
function toString()
{
return "DrawStyle " + this.className;
}
}